package com.dbsop.service.impl;

import com.dbsop.domain.EsCondition;
import com.dbsop.entity.Student;
import com.dbsop.mapper.StudentMapper;
import com.dbsop.service.StudentService;
import com.dbsop.util.DataGenUtils;
import com.dbsop.util.IdGenerate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    StudentMapper studentMapper;

    @Override
    public void testData() {
        List<Student> studentList = new ArrayList<>();
        for (int i = 0; i < 10000; i++) {
            Student student = new Student();
            student.setNumber(IdGenerate.getUId());
            student.setName(DataGenUtils.genName());
            student.setAddress("中国");
            student.setAge(DataGenUtils.age());
            student.setGrade(DataGenUtils.grade());
            student.setShift(DataGenUtils.shift());
            student.setTranscripts(DataGenUtils.subjects());
            studentList.add(student);
        }
        studentMapper.saveBatch(studentList);
    }

    @Override
    public void list() {
        EsCondition esCondition = EsCondition.getEsCondition();
        esCondition.size(100);
        esCondition.eq("transcripts.subjectsName","");
//        esCondition.addIndex();
        List<Student> studentList = studentMapper.selectList(esCondition);
        System.out.println(1);
    }

    @Override
    public void page() {
        EsCondition esCondition = EsCondition.getEsCondition();
        esCondition.eq("year",2019);
//        ESPage<PreDayRainfall> preDayRainfallESPage = preDayRainfallMapper.selectPageList(esCondition, 0, 0);
        System.out.println(1);
    }
}
